//
//  BCGotCommitView.m
//  BangcaiDriver
//
//  Created by apple on 16/9/20.
//  Copyright © 2016年 BC. All rights reserved.
//

#import "BCGotCommitView.h"
#import "BCGotCommitChooseV.h"
#import "BCGotCommitCell.h"

@interface BCGotCommitView  ()<UITableViewDelegate, UITableViewDataSource, chooseDelegate>
@property(nonatomic, strong)UIButton *ringBut;
@property(nonatomic, strong)UIButton *goGetCommitBut;
@property(nonatomic, strong)UITableView *table;
@property(nonatomic, assign)NSInteger tableCount;
@end

@implementation BCGotCommitView

- (void)createView
{
    
    UIView *headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 64)];
    [self addSubview:headView];
    
    self.ringBut = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.ringBut setImage:[UIImage imageNamed:@"消息"] forState:UIControlStateNormal];
    self.goGetCommitBut = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.goGetCommitBut setBackgroundImage:[UIImage imageNamed:@"lv"] forState:UIControlStateNormal];
    [self.goGetCommitBut setBackgroundImage:[UIImage imageNamed:@"接单"] forState:UIControlStateSelected];

    [self.goGetCommitBut setTitle:@"我要接单" forState:UIControlStateNormal];
    [self.goGetCommitBut setTitle:@"停止接单" forState:UIControlStateSelected];

    [self.goGetCommitBut addTarget:self action:@selector(goGetCommit:) forControlEvents:UIControlEventTouchUpInside];
    self.goGetCommitBut.tintColor = [UIColor whiteColor];
    self.goGetCommitBut.titleLabel.font = [UIFont systemFontOfSize:12];
    UILabel *titleLab = [[UILabel alloc] init];
    titleLab.text = @"订单";
    titleLab.font = [UIFont boldSystemFontOfSize:18];
    UILabel *headLine = [[UILabel alloc] init];
    headLine.backgroundColor = [UIColor colorWithRed:0.820 green:0.820 blue:0.820 alpha:1];
    [headView addSubview:headLine];
    [headView addSubview:self.ringBut];
    [headView addSubview:self.goGetCommitBut];
    [headView addSubview:titleLab];
    
    [titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(0);
        make.centerY.mas_equalTo(10);
    }];
    
    [self.ringBut mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(10);
        make.left.mas_equalTo(8);
        make.width.and.height.mas_equalTo(45);
    }];
    
    [self.goGetCommitBut mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(10);
        make.right.mas_equalTo(-8);
        
    }];
    
    [headLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(0);
        make.height.mas_equalTo(2);
        make.width.mas_equalTo(SCREEN_WIDTH);
        make.left.mas_equalTo(0);
    }];
    
    BCGotCommitChooseV *chooseView = [[BCGotCommitChooseV alloc] init];
    chooseView.delegate = self;
    chooseView.backgroundColor = [UIColor colorWithRed:0.980 green:0.980 blue:0.980 alpha:1];
    [self addSubview:chooseView];
    [chooseView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(headView.mas_bottom);
        make.height.mas_equalTo(90);
        make.width.mas_equalTo(SCREEN_WIDTH);
    }];
    
    self.table = [[UITableView alloc] initWithFrame:CGRectMake(0, 154, SCREEN_WIDTH, SCREEN_HEIGHT - 154 - 50) style:UITableViewStylePlain];
    self.table.delegate = self;
    self.table.dataSource = self;
    [self.table registerClass:[BCGotCommitCell class] forCellReuseIdentifier:@"reuse"];
    [self addSubview:self.table];
    
    self.tableCount = 4;
}

- (void)goGetCommit:(UIButton *)button{
    button.selected = !button.selected;
       
}

- (void)chooseDate:(NSInteger)style{
    switch (style) {
        case 0:
            self.tableCount = 2;
            break;
        case 1:
            self.tableCount = 3;
            break;
        case 2:
            self.tableCount = 4;
            break;
        default:
            break;
    }
    [self.table reloadData];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.tableCount;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [self.delegate clickWithIndex:indexPath];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return indexPath.row *30 +100;
}

- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    BCGotCommitCell *cell = [tableView dequeueReusableCellWithIdentifier:@"reuse"];
    cell.timeLab.text = [NSString stringWithFormat:@"0%ld:00", indexPath.row];
    cell.letter = @"长兴市场5号门 -- 长兴市场5号门集市 -- 长兴市场5号门 -- 长兴市场5号门集市 -- 渔港制造(星海广场)";
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    if (indexPath.row == 0) {
        cell.topLine.hidden = YES;
    }else{
        cell.topLine.hidden = NO;
    }
    
    if (indexPath.row == 3) {
        cell.bottomLine.hidden = YES;
    }else{
        cell.bottomLine.hidden = NO;
    }
    return cell;
    
    
    
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
